package com.lin.cli.command;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONUtil;
import com.lin.generator.MainGenerator;
import com.lin.model.DataModel;
import lombok.Data;
import picocli.CommandLine;

import java.util.concurrent.Callable;

/**
 * 读取json文件生成代码
 */
@CommandLine.Command(name = "json-generate", description = "读取json文件生成代码", mixinStandardHelpOptions = true)
@Data
public class JsonGenerateCommand implements Callable {



    @CommandLine.Option(names = {"-f", "--file"}, description = "读取json文件生成代码",interactive = true, arity = "0..1",echo = true)
    public String filePath;

    @Override
    public Object call() throws Exception {
        String jsonStr = FileUtil.readUtf8String(filePath);
        DataModel dataModel = JSONUtil.toBean(jsonStr, DataModel.class);
        MainGenerator.doGenerator(dataModel);
        return null;
    }
}
